﻿namespace Sidvall.IdentityManager.Data
{
	public sealed class PluginFilterCollection : System.Collections.ObjectModel.KeyedCollection<string, PluginFilter>
	{
		#region Public Members

		#region Add

		public PluginFilter Add(string pluginId, int filterIndex, string filterContext, PluginFilterResult filterResult)
		{
			PluginFilter item;

			item = new PluginFilter()
			{
				PluginId = pluginId,
				FilterIndex = filterIndex,
				FilterContext = filterContext,
				FilterResult = filterResult,
			};
			Add(item);
			return item;
		}

		#endregion
		#region FindItemById

		public PluginFilter FindItemById(string pluginId)
		{
			if (string.IsNullOrWhiteSpace(pluginId))
				return null;
			if (!Contains(pluginId))
				return null;
			return this[pluginId];
		}

		#endregion
		#region GetKeyForItem

		protected override string GetKeyForItem(PluginFilter item)
		{
			if (item == null)
				throw new System.ArgumentNullException("item");
			return item.PluginId;
		}

		#endregion

		#endregion
		#region Constructors

		public PluginFilterCollection()
			: base(System.StringComparer.OrdinalIgnoreCase)
		{
		}

		#endregion
	}
}
